//
//  AppUtils.m
//  SVN_Tuan_Thuy
//
//  Created by HOCVIEN on 4/21/15.
//  Copyright (c) 2015 Module4. All rights reserved.
//

#import "AppUtils.h"
#import "Food.h"
static AppUtils *instance;
@implementation AppUtils

+ (AppUtils *)defaultAppUtils {
    if (!instance) {
        instance = [[AppUtils alloc] init];
        instance.foodList = [[NSMutableArray alloc] init];
        instance.foodListId = [[NSMutableArray alloc] init];
    }
    return instance;
}

- (void)loadData:(void (^)(NSMutableArray *, NSError *))callback {
    NSURL *url = [NSURL URLWithString:@"http://food2fork.com/api/search?key=cbabb661c0146d117f6ab6866c6017ed"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSError *error;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
        NSMutableArray *array = [dic objectForKey:@"recipes"];
        //NSLog(@"%@",array);
        for (NSDictionary *food in array) {
            Food *f = [[Food alloc]initWithDictionary:food];
            [self.foodList addObject:f];
            [self.foodListId addObject:f.foodID];
        }
        callback(self.foodList,error);
    }];
}

+ (UIColor *)themeColor {
    return [UIColor colorWithRed:0.961 green:0.651 blue:0.137 alpha:1];
}
+ (UIColor *)themeFontColor {
    return [UIColor colorWithRed:0.353 green:0.224 blue:0.016 alpha:0.6f];
}
@end
